package producer.config;

import common.util.IPUtil;
import org.apache.zookeeper.CreateMode;
import producer.entity.RegisterConfigOuterClass;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @ClassName RegisterConfig
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2022/1/11 上午12:16
 * @Version V1.0
 * @Since JDK 11
 */
public class RegisterConfig {

    public void register() throws Exception {
        //注册节点
        //注册信息
        //ip port
        String hostAddress = IPUtil.getInet4Address().getHostAddress();
        RegisterConfigOuterClass.RegisterConfig registerConfig = RegisterConfigOuterClass.RegisterConfig.newBuilder().setHost(hostAddress).setPort(AppConfig.port).build();
        ZKConfig.client.create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
                .forPath("/"+AppConfig.group+"/"+AppConfig.version+"/"+AppConfig.name,registerConfig.toByteArray());
    }
}
